$(function(){
	$(".header .header-right input").keydown(function(evt){
	let e=evt|| event;
	let keyValue=e.charCode || e.keyCode || e.which;
	if(keyValue==13 && $(".header .header-right input").val()){
		let str=`<ul>
					    	<li>
					    		<em></em>
					    		<input type="checkbox"  />
					    		<p>${$(".header-right input").val()}</p>
					    		<a ><span>-</span></a>
					    	</li>
					    </ul>`;
		$("#realizingContainer").append(str);			    
		addNode();
		deleteNode();
		$(".header .header-right input").val("");
	}
	success();
})
	 
	function success(){
		    $("#realizingContainer ul li input[type=checkbox]").click(function(){
			$(".tool-success .success-container").append($(this).parent().parent());
			addNode();
			addNode2();
			deleteNode2();
	      })
		    
	}
	
	function deleteNode(){
		$("#realizingContainer ul li a").click(function(){
			$(this).parent().remove();
	    addNode();
		})
		
	}
	function addNode(){
		   let len=$("#realizingContainer ul li").length;	
			$("#realizingTitle .realizing-title-right span").html(len);
		
	}
    function deleteNode2(){
    	   $(".success-container ul li a").click(function(){
			$(this).parent().remove();
	        addNode2();
		})
    }
	function addNode2(){
		   let len=$(".success-container ul li").length;
			$(".success-right span").html(len);
		
	}
	
	
	
	//保存在cookie中
	function setcookie(){
		        $.removeCookie("inputValue");
				let len=$("#realizingContainer p").length;
				for(let i=0;i<len;i++){   
					if($.cookie("inputValue")){
						$.cookie("inputValue",$.cookie("inputValue")+";"+$("#realizingContainer p").eq(i).html(),{expires:999});
					}else{
						$.cookie("inputValue",$("#realizingContainer p").eq(i).html(),{expires:999});
					}
				}
	   }
    function setcookie2(){
		        $.removeCookie("successValue");
				let len=$(".success-container ul li p").length;
				for(let i=0;i<len;i++){   
					if($.cookie("successValue")){
						$.cookie("successValue",$.cookie("successValue")+";"+$(".success-container ul li p").eq(i).html(),{expires:999});
					}else{
						$.cookie("successValue",$(".success-container ul li p").eq(i).html(),{expires:999});
					}
				}
	   }

	function getCookie(){
		if($.cookie("inputValue")){
			let cookieValue=$.cookie("inputValue");
			let cookieSingle=cookieValue.split(";");
			for(let i=0;i<cookieSingle.length;i++){
				let strCookie=`<ul>
					    	<li>
					    		<em></em>
					    		<input type="checkbox"  />
					    		<p>${cookieSingle[i]}</p>
					    		<a ><span>-</span></a>
					    	</li>
					    </ul>`;
		     $("#realizingContainer").append(strCookie);	
			}
			
		}
		addNode2();
		deleteNode2();
		success();
	}
	function getCookie2(){
		if($.cookie("successValue")){
			let cookieValue=$.cookie("successValue");
			let cookieSingle=cookieValue.split(";");
			for(let i=0;i<cookieSingle.length;i++){
				let strCookie=`<ul>
					    	<li>
					    		<em></em>
					    		<input type="checkbox" checked />
					    		<p>${cookieSingle[i]}</p>
					    		<a ><span>-</span></a>
					    	</li>
					    </ul>`;
		     $(".success-container").append(strCookie);	
			}
			
		}
		addNode2();
		deleteNode2();
	}
	$(window).bind("beforeunload",function(){
		setcookie();
		setcookie2();
	})
	getCookie();
	getCookie2();
})

